package com.franklin.validation.core.support;

import com.franklin.validation.core.argument.impl.ResultFactoryImpl;
import com.franklin.validation.core.argument.resolvers.ParamCheckHandlerArgumentResolver;
import com.franklin.validation.core.argument.resolvers.ParamCheckHandlerArgumentResolverV2;
import com.franklin.validation.core.cache.RequestMultiValueCache;
import com.franklin.validation.core.webflux.filter.ArgumentFilter;
import com.franklin.validation.core.webflux.handler.ParamCheckExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
import org.springframework.web.server.WebFilter;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/11 15:19
 */
@ConditionalOnMissingBean(WebFluxFormDataSupport.class)
@Import({WFFDComponentPackageScan.class, ResultFactoryImpl.class})
public class WebFluxFormDataSupport implements WebFluxConfigurer {

    @Autowired
    private ParamCheckHandlerArgumentResolverV2 resolverV2;

    @Override
    public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
        configurer.addCustomResolver(resolverV2);
    }

    @Bean
    @Order(Integer.MIN_VALUE)
    @ConditionalOnMissingBean(ArgumentFilter.class)
    public WebFilter argumentFilter(){
        return new ArgumentFilter();
    }

    @Bean
    @ConditionalOnMissingBean(ParamCheckExceptionHandler.class)
    public ParamCheckExceptionHandler paramCheckExceptionHandler(){
        return new ParamCheckExceptionHandler();
    }
}
